const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
function InitTime(endtime){
    var dd,hh,mm,ss = null;
    var time = (new Date(endtime).getTime() - new Date().getTime())/1000;
    if(time<=0){
        return 0
    }else{
        dd = Math.floor(time / 60 / 60 / 24);
        hh = Math.floor((time / 60 / 60) % 24);
        mm = Math.floor((time / 60) % 60);
        ss = Math.floor(time  % 60);
        var str = dd+"天"+hh+":"+mm+":"+ss;
        return str;
    }
}
var time1='';
Page({
  data: {
    id:'',
    detail:'',
    logisticsdata:[],
    lognum:'',
    logisticsCompany:'',
  },
  onLoad(options) {
    if(options.id){
      this.setData({
        id:options.id
      })
      this.refunddetail()
    }
    if(options.parentid){
      app.globalData.parentid=options.parentid
    }
    // this.logistics()
  },
  refunddetail(){
    Controller.refunddetail({orderNumber:this.data.id}).then(res=>{
      if(res.data.baseData){
        if(res.data.baseData.imgUrls){
        res.data.baseData.imgUrls=res.data.baseData.imgUrls.split(",")
        }
        // if(res.data.baseData.reserveTime){
        // res.data.baseData.downtime=InitTime(res.data.baseData.reserveTime.replace(/-/g, '/'))
        // }
        this.setData({
          detail:res.data.baseData,
        })
      }
    })
  },
  cancelafter(e){
    var id=this.data.id;
    var that=this;
    wx.showModal({
      title: '提示',
      content: '是否取消退款?',
      success(res) {
        if (res.confirm) {
          var data={
            orderNumber:id
          }
          Controller.refundcancel(data).then(res=>{
            wx.showToast({
              title:"取消成功"
            })
            setTimeout(()=>{
              wx.redirectTo({
                url:'/pages/Me/order'
              })
            },1000)
          })
        }
      }
    })
  },
  goshipper(){
    wx.redirectTo({
      url:'/pages/service/address?id='+this.data.id
    })
  },
  onShareAppMessage: function (e) {
    let title = '';
    let imageUrl = '';
    let path=app.getCurrentPageUrlWithArgs()
    let obj = {
      title,
      imageUrl,
      path,
      success: function (res) {},
      fail(err) {}
    }
    return obj
  },
  onShareTimeline: function(res){
    let title = '';
    let imageUrl = '';
    let path=app.getCurrentPageUrlWithArgs()
    let obj = {
      title,
      imageUrl,
      path,
      success: function (res) {},
      fail(err) {}
    }
    return obj
  },

})